<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Service_model extends CI_Model {
    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
  
	function show_services(){
		$this->load->database(); 
		$query = $this->db->get('tbservices');
		if($query->num_rows() > 0){
			return $query->result();
		}else{
			return null;
		}
	}
	
	function get_servicescommand($apptype){
		$this->load->database(); 
		$this->db->where('apptype',$apptype);
		$query = $this->db->get('tbservices');
		if($query->num_rows() > 0){
			return $query->result();
		}else{
			return null;
		}
	}
	
	function get_servicesrandom($type){
		$this->load->database(); 
		$this->db->where('apptype',$type);
		$this->db->order_by('id',"desc");
		$this->db->limit(1); 
		$query = $this->db->get('tbservices');
		if($query->num_rows() > 0){
			return $query->result();
		}else{
			return null;
		}
	}
	/*
	 *  type = 1: iphone
	 *  type = 2: android
	 *  type = 3: blackbery
	 */
	function get_servicesbytype($type){
		$this->load->database(); 
		$this->db->limit(1); 
		$this->db->where('apptype',$type);
		$query = $this->db->get('tbservices');
		if($query->num_rows() > 0){
			return $query->result();
		}else{
			return null;
		}
	}
 
 
	function add_services($shortcode,$prefix_1,$prefix_2,$return_value,$partner,$type){
		$this->load->database();
    	$data = array( 
            'shortcode'=>$shortcode,
            'prefix_1'=>$prefix_1,
    		'prefix_2'=>$prefix_2,
    		'return_value'=>$return_value, 
    		'partner'=>$partner,
    		'apptype'=>$type,
    		'active'=>1
            );
    	$this->db->insert('tbservices', $data); 
	}
	
	function delservices($id){
		$this->load->database();
		$this->db->where(array(
			'id'=>$id 
		));
		$this->db->delete('tbservices');
	}
	
	
	function show_mtresult(){
		$this->load->database(); 
		$query = $this->db->get('tbmtfile');
		if($query->num_rows() > 0){
			return $query->result();
		}else{
			return null;
		}
	}
	
	function add_mtresult($name,$serviceid,$mtresult,$mtfile){
		$this->load->database();
    	$data = array( 
            'name'=>$name,
            'serviceid'=>$serviceid,
    		'mtresult'=>$mtresult,
    		'mtfile'=>$mtfile
            );
    	$this->db->insert('tbmtfile', $data); 
	}
	
	 
}
    ?>